package server;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import util.NetworkUtil;

import command.IResponse;
import command.protobuf.GetUserTimelineResponseProtoBuf.*;

public class GetUserTimelineResponse implements IResponse {
	public static short cmdType = -1;
	private static final GetUserTimelineRes.Builder builder = GetUserTimelineRes
			.newBuilder();

	GetUserTimelineRes res = null;

	@Override
	public void read(InputStream input) {
		try {
			byte isNull = (byte) input.read();
			if (isNull == 1)
				return;
			
			res = GetUserTimelineRes.parseFrom(input);
		} catch (IOException e) {
			res = null;
		}
	}

	@Override
	public void write(OutputStream output) {
		try {
			if (res != null) {
				output.write(0);
				res.writeTo(output);
			} else
				output.write(1);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public Object get() {
		if (res == null)
			return null;
		return res.getTweetList();
	}

	@Override
	public void set(Object content) {
		res = (GetUserTimelineRes) content;
	}

	@Override
	public short getCmdType() {
		// TODO Auto-generated method stub
		return 0;
	}

}
